<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <ul>
      <li><a data-url="/a">a</a></li>
      <li><a data-url="/b">b</a></li>
      <li><a data-url="/c">c</a></li>
    </ul>
    <div id="contentBox"></div>
    <script>
      let routerData = [
        { path: '/a', pathData: '内容a' },
        { path: '/b', pathData: '内容b' },
        { path: '/c', pathData: '内容c' },
      ];
      let btn = document.getElementsByTagName('a');
      let content = document.getElementById('contentBox');
      let path;
      for (let i = 0; i < btn.length; i++) {
        btn[i].addEventListener('click', function () {
          console.log(this.getAttribute('data-url'));
          path = this.getAttribute('data-url');
          window.location.hash = path;
          console.log(window.location);
        });
      }
      window.addEventListener('hashchange', function () {
        routerData.map((item) => {
          if (item.path === path) {
            content.innerHTML = item.pathData;
          }
        });
      });
    </script>
  </body>
</html>
